<template>
    <div class="Records">
        <!--        面包导航-->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>寝室管理</el-breadcrumb-item>
            <el-breadcrumb-item>报修记录</el-breadcrumb-item>
        </el-breadcrumb>

        <!--        卡片-->
        <el-card class="box-card">
            <!--            搜索区域-->
            <el-row :gutter="20">
                <el-col :span="3">
                    <el-select v-model="queryInfo.statues" placeholder="处理状态" clearable>
                        <el-option
                                v-for="item in st"
                                :key="item.id"
                                :label="item.sname"
                                :value="item.id">
                        </el-option>
                    </el-select>
                </el-col>
                <el-col :span="8">
                    <el-input placeholder="请输入姓名"  v-model="queryInfo.name" clearable>
                        <el-button slot="append" icon="el-icon-search" @click="search" ></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <!--            表格区域-->
            <el-table :data="recardList" border>
                <el-table-column type="index"></el-table-column>
                <el-table-column label="姓名" prop="name"></el-table-column>
                <el-table-column label="楼栋" prop="bname"></el-table-column>
                <el-table-column label="寝室名字" prop="qname"></el-table-column>
                <el-table-column label="物品名字" prop="iname"></el-table-column>
                <el-table-column label="描述" prop="describe"></el-table-column>
                <el-table-column label="状态" prop="statues">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.statues ===0">未处理</el-tag>
                        <el-tag type="success" v-else-if="scope.row.statues ===1">已处理</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作"  width="180px">
                    <template slot-scope="scope">
                        <!--                            修改-->
                        <el-button type="primary" icon="el-icon-edit" size="mini" @click="resove(scope.row)"></el-button>
<!--                        查看-->
                        <el-tooltip effect="dark" content="查看图片" placement="top" :enterable="false">
                            <el-button type="warning" icon="el-icon-edit" size="mini" @click="isShowimage = true"></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
            <!--                分页-->
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="queryInfo.page"
                    :page-sizes="[5,10,20,50]"
                    :page-size="queryInfo.size"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </el-card>
            <div v-show="isShowimage">
                <el-image :src="src"></el-image>
            </div>
        <el-dialog
                title="修改信息"
                :visible.sync="isShowimage"
                width="50%" >
<!--            <el-image src="D:/user/7a7d77f7-dd96-409c-a20b-844a117d0f1b.png"></el-image>-->
            <img src="~@/assets/img/4caacf0e-ba71-4666-a2a4-c6b799a644d2.png">
<!--            <img src="http://localhost:8080/D:/user/7a7d77f7-dd96-409c-a20b-844a117d0f1b.png">-->
            <span slot="footer" class="dialog-footer">
    <el-button @click="isShowimage = false">取 消</el-button>
    <el-button type="primary" @click="isShowimage = false">确 定</el-button>
  </span>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name: "Records",
        data(){
            return{
                isShowimage: false,
                // eslint-disable-next-line no-undef
                src: '',
                queryInfo:{
                    page: 1,
                    size: 10,
                    statues: '',
                    name: '',
                },
                total: 0,
                recardList: [],
                st:[
                    {
                        id: 1,
                        sname: '已处理'
                    },{
                         id: 0,
                        sname: '未处理'
                    }
                ],

            }
        },
        created() {
            this.getAllrecords()
        },
        methods:{
            async getAllrecords(){
                const {data: res} = await this.$http.get('Departments/getAllRecard',{
                    params: this.queryInfo
                })
                if(res.code !== 200) return this.$message.error(res.message)
                this.recardList = res.data.data
            },
            //监听pagesize的改变
            handleSizeChange(newSize){
                this.queryInfo.size = newSize
                this.getAllrecords()
            },
            //页码值改变
            handleCurrentChange(newPage){
                this.queryInfo.page = newPage
                this.getAllrecords()
            },
            //搜索
            async search(){
                const {data: res} = await this.$http.get('Departments/getAllRecard',{
                    params: this.queryInfo
                })
                if(res.code !== 200) return this.$message.error(res.message)
                this.recardList = res.data.data
            },
            //修改状态
            async resove(mid){
                const confirm = await this.$confirm('此操作将永久修改维修状态, 是否已经维修好?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).catch(err =>{
                    return err
                })
                if(confirm !== 'confirm') return this.$message.info('已取消删除')
                const {data:res} = await this.$http.get('Departments/updateRecard',{
                    params:{
                        id: mid.id
                    }
                })
                if(res.code !== 0) return this.$message.error(res.message)
                this.$message.success(res.message)
                this.getAllrecords()
            },
            show(url){
                this.src = url.imgurl
                this.isShowimage = true;
            }
        }
    }
</script>

<style scoped>

</style>